package liumengbaio.lolzhangyoubao.Activity.utils;


import android.content.Context;

import org.json.JSONArray;
import org.json.JSONObject;

import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;

import liumengbaio.lolzhangyoubao.Activity.InFo.HeroSkillInfo;

/**
 * 召唤师技能的获取方法
 * Created by lanouhn on 16/9/1.
 */
public class HeroSkillsUtils {
    public static List<HeroSkillInfo> getSummonerSkillsInfoList(Context mContext) {
        List<HeroSkillInfo> lssi = getSummonerSkillsInfo(mContext);
        return lssi;
    }

    public static List<HeroSkillInfo> getSummonerSkillsInfo(Context mContext) {

        List<HeroSkillInfo> lssi = new ArrayList<>();
        try {
            InputStream is = mContext.getAssets().open("skills/heroskills.json");
            byte[] buffer = new byte[is.available()];
            is.read(buffer);
            is.close();

            String text = new String(buffer, "UTF-8");
            JSONObject mObject = new JSONObject(text);
            JSONArray array = mObject.getJSONArray("data");

            for (int i = 0; i < array.length(); i++) {
                HeroSkillInfo ssi = new HeroSkillInfo();
                JSONObject object1 = array.getJSONObject(i);
                ssi.setId(object1.getString("id"));
                ssi.setRole_id(object1.getString("role_id"));
                ssi.setName(object1.getString("name"));
                ssi.setKey(object1.getString("key"));
                ssi.setPic_url(object1.getString("pic_url"));
                lssi.add(ssi);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return lssi;
    }

}
